import api from "../api/index"
import { isNull } from '../utils/index'

// 常量
const constant = {
  /** token key*/
  TOKEN: "token",
  /** 刷新token key */
  REFRESH_TOKEN: "refreshToken",
  /** 过期时间 key */
  EXPIRES_TIME: "expiresTime",
  USER_INFO: "userInfo",
  LOGIN_NOT_LOGIN: 0,
  LOGIN_SUCCESS: 1,
  LOGIN_NOT_REGISTER: 2,
  
	COLOR_LIST: [{
		title: '嫣红',
		name: 'red',
		color: '#e54d42',
		class: ''
	},
	{
		title: '桔橙',
		name: 'orange',
		color: '#f37b1d',
		class: 'warning'
	},
	{
		title: '明黄',
		name: 'yellow',
		color: '#fbbd08'
	},
	{
		title: '橄榄',
		name: 'olive',
		color: '#8dc63f',
		class: 'success'
	},
	{
		title: '森绿',
		name: 'green',
		color: '#39b54a'
	},
	{
		title: '天青',
		name: 'cyan',
		color: '#1cbbb4'
	},
	{
		title: '海蓝',
		name: 'blue',
		color: '#0081ff',
		class: 'primary'
	},
	{
		title: '姹紫',
		name: 'purple',
		color: '#6739b6'
	},
	{
		title: '木槿',
		name: 'mauve',
		color: '#9c26b0'
	},
	{
		title: '桃粉',
		name: 'pink',
		color: '#e03997'
	},
	{
		title: '棕褐',
		name: 'brown',
		color: '#a5673f'
	},
	{
		title: '玄灰',
		name: 'grey',
		color: '#8799a3',
		class: 'info'
	},
	{
		title: '草灰',
		name: 'gray',
		color: '#aaaaaa'
	},
	{
		title: '墨黑',
		name: 'black',
		color: '#333333'
	},
	{
		title: '雅白',
		name: 'white',
		color: '#ffffff'
	},
  ],
  AGE_RANGE: ()=>{
    let ages = []
    for(let i=18; i<78; i++){
      ages.push(i)
    }
    return ages
  },
  WEIGHT_RANGE: ()=>{
    let weights = []
    for(let i = 30; i<140; i++){
      weights.push(i)
    }
    return weights
  },
  HEIGHT_RANGE: ()=>{
    let heights = []
    for(let i =130; i<221;  i++){
      heights.push(i)
    }
    return heights;
  },
  W_EDU_RANGE: ()=>{
    let edu = wx.getStorageSync('wEduRange')
    if(edu){
      return JSON.parse(edu)
    }else{
      let token = wx.getStorageSync(constant.TOKEN)
      if(!isNull(token)){
        edu = []
        api.common.getDictData('user_need_education').then(res=>{
          for(const i in res){
            edu.push({
              name: res[i].dictLabel,
              val: res[i].dictValue
            })
          }
          wx.setStorageSync('wEduRange', JSON.stringify(edu))
          return edu
        })
      }
    }
  },
  W_INCOME_RANGE: ()=>{
    let income = wx.getStorageSync('wIncomeRange')
    if(income){
      return JSON.parse(income)
    }else{
      let token = wx.getStorageSync(constant.TOKEN)
      if(!isNull(token)){
        income = []
        api.common.getDictData('user_need_income').then(res=>{
          for(const i in res){
            income.push({
              name: res[i].dictLabel,
              val: res[i].dictValue
            })
          }
        wx.setStorageSync('wIncomeRange', JSON.stringify(income))
        return income
        })
    }
  }
}
}

export default constant;

